package me.zhengjie.pm.taskprogress.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import me.zhengjie.aop.log.Log;
import me.zhengjie.hr.employeebase.domain.EmployeeBase;
import me.zhengjie.hr.employeebase.service.EmployeeBaseService;
import me.zhengjie.hr.employeebase.service.dto.EmployeeBaseQueryCriteria;
import me.zhengjie.pm.projectbase.domain.ProjectBase;
import me.zhengjie.pm.projectbase.service.ProjectBaseService;
import me.zhengjie.pm.projectbase.service.dto.ProjectBaseQueryCriteria;
import me.zhengjie.pm.taskprogress.service.TaskProgressService;
import me.zhengjie.pm.taskprogress.service.dto.TaskProgressQueryCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Api(tags = "周报数据统计")
@RestController
@RequestMapping("/api/workhoursStatistics")
public class WorkhoursStatisticsController {

    @Autowired
    private TaskProgressService taskProgressService;

    @Autowired
    private ProjectBaseService projectBaseService;

    @Autowired
    private EmployeeBaseService employeeBaseService;

    public WorkhoursStatisticsController() {
    }

    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/download")
    @PreAuthorize("@el.check('taskProgress:list')")
    public void download(HttpServletResponse response, TaskProgressQueryCriteria criteria) throws IOException {
        //暂时不对项目的时间做限制，查询全部项目
        ProjectBaseQueryCriteria projectCriteria = new ProjectBaseQueryCriteria();
        EmployeeBaseQueryCriteria employeeCriteria = new EmployeeBaseQueryCriteria();
        //0为未离职
        employeeCriteria.setIsLeave("0");
        taskProgressService.workhoursDownload(taskProgressService.queryAll(criteria),
                projectBaseService.queryAll(projectCriteria),
                employeeBaseService.queryAll(employeeCriteria),
                response);
    }
}
